/**
 * 组件注册文件，只处理一级目录的组件，如果组件中设置了name则优先使用name，如果没设置则使用文件夹名作为组件名
 */
import {
    Form,
    Input,
    Select,
    DatePicker,
    Switch,
    Radio,
    Checkbox,
    Button,
    Menu,
    Space,
    Divider,
    InputNumber,
    Spin,
    Popconfirm,
    Tabs,
    Dropdown,
    Table,
    Modal,
    Upload,
    Image
} from 'ant-design-vue';

/**
 * 所有的组件
 */
const files = require.context('./', true, /\.vue$/);

/**
 * 注册方法
 */
export default app => {
    [Form, Input, Select, InputNumber, Spin, Divider, DatePicker, Space, Switch, Radio, Checkbox, Button, Menu, Popconfirm, Tabs, Dropdown, Table, Modal, Upload, Image].forEach(item => app.use(item));
    files.keys().forEach(key => {
        const paths = key.split('/');
        if (paths.length > 3) return;   //如果不是一级目录则跳过
        const name = paths[1];  //文件夹名称
        const component = files(key).default || files(key);
        app.component(component.name || name, component);
    });
}